package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.vo.ValueSkuVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.product.eneity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{


    /**
     * 根据spuId获取销售属性的值和名
     * @param spuId
     * @return
     */
    @Override
    public List<SpuSaleAttr> getSpuSaleAttrAndValue(Long spuId) {

        return baseMapper.getSpuSaleAttrAndValue(spuId);
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrANdValueAndOrder(Long spuId , Long skuId) {

        return baseMapper.getSpuSaleAttrAndValueAndOrder(spuId , skuId);
    }

    @Override
    public String getValueJson(Long spuId) {
        List<ValueSkuVo> list = baseMapper.getValueJson(spuId);
        Map<String, Long> map = list.stream().collect(Collectors.toMap(t -> t.getValueJson(), t -> t.getSkuId()));
        String s = JSON.toJSONString(map);
        return s;
    }
}




